<?php
class GoodsController extends Controller{
	public function actionIndex($id){
		$mod = new GoodsModel();
		$goods = $mod->get_by_key($id);
		if(isset($goods['cate']) && !empty($goods['cate'])){
			$cate_lists = GoodsCateModel::getCateFamilyLists($goods['cate']);
			$this->assign('cate_lists', $cate_lists);
		}
		if(isset($goods['tpl_view'])){
			$view = $goods['tpl_view'];
		}else{
			$view = 'view';
		}
		
		$goods_list = Goods::model()->findAll(
			array(
				'condition' => 'goods_id=:goods_id',
				'params'	=> array(':goods_id'=>$id),
				'index'		=> 'id',
				'select'	=> 'id,stock,price' 
			)
		);
		
		$this->pageTitle = $goods['name'] . ' - ' . Yii::app()->name;
		$this->render($view, array(
			'goods'			=> $goods,
			'goods_list' 	=> $goods_list
		));
	}
	
	public function actionCate($id){
		$mod = new GoodsModel();
		$goods = $mod->get_by_key($id);
		if(isset($goods['cate']) && !empty($goods['cate'])){
			$cate_lists = GoodsCateModel::getCateFamilyLists($goods['cate']);
			$this->assign('cate_lists', $cate_lists);
		}
		if(isset($goods['tpl_view'])){
			$view = $goods['tpl_view'];
		}else{
			$view = 'view';
		}
		
		$goods_list = Goods::model()->findAll(
			array(
				'condition' => 'goods_id=:goods_id',
				'params'	=> array(':goods_id'=>$id),
				'index'		=> 'id',
				'select'	=> 'id,stock,price' 
			)
		);
		
		$this->pageTitle = $goods['name'] . ' - ' . Yii::app()->name;
		$this->render($view, array(
			'goods'			=> $goods,
			'goods_list' 	=> $goods_list
		));
	}
}
?>